package com.demo.transaction;

import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.transaction.TransactionManager;

import javax.sql.DataSource;
import java.util.List;
import java.util.Map;

@SpringBootApplication
@MapperScan(basePackages = {"com.demo.transaction.dao"})
public class TransactionMain implements CommandLineRunner {

    @Autowired
    List<DataSource> dataSources;

    public static void main(String[] args) {
        ConfigurableApplicationContext run = SpringApplication.run(TransactionMain.class, args);

        /**
         * dateSource，sqlSessionFactory，transactionManager
         * */
        Map<String, DataSource> dMap = run.getBeansOfType(DataSource.class);
        Map<String, SqlSessionFactory> sMap = run.getBeansOfType(SqlSessionFactory.class);
        Map<String, TransactionManager> tMap = run.getBeansOfType(TransactionManager.class);
    }

    public void run(String... args) throws Exception {
        System.out.println( dataSources );
    }
}
